package com.liunian.test;

import java.util.Arrays;

public class EraseOverlapIntervals435 {

	public int eraseOverlapIntervals(int[][] intervals) {
		Arrays.sort(intervals, (a, b) -> {
			if (a[0] == b[0]) {
				return a[1] - b[1];
			}
			return a[0] - b[0];
		});
		int res = 0;
		for (int i = 1; i < intervals.length; i++) {
			if (intervals[i][0] < intervals[i - 1][1]) {
				res++;
				intervals[i][1] = Math.min(intervals[i][1], intervals[i - 1][1]);
			}
		}
		return res;
	}

}
